#include "RootItem.h"



namespace
{
QString FILEPATH_FIELD_NAME = "filepath";
}



RootItem::RootItem(QObject *parent) :
    AbstractItem(parent)
{
    d = new Data();
    connect(this, SIGNAL(sigDirty()), this, SLOT(setDirty()));
}



RootItem::RootItem(const QString& name, QObject *parent) :
    AbstractItem(parent)
{
    d = new Data();
    setData(NameData, name);
    connect(this, SIGNAL(sigDirty()), this, SLOT(setDirty()));
}



void RootItem::setFilePath(const QString &file_path)
{
    setData(FileData, file_path);
}



QString RootItem::filePath() const
{
    return data(FileData).toString();
}



int RootItem::fieldCount() const
{
    return (RootItem::DataType_LAST - AbstractItem::DataType_FIRST + 1);
}



QString RootItem::fieldName(const int &field) const
{
    switch (field)
    {
    case RootItem::FileData: return FILEPATH_FIELD_NAME;
    }

    return AbstractItem::fieldName(field);
}



int RootItem::field(const QString &field_name) const
{
    if (field_name == FILEPATH_FIELD_NAME) return FileData;

    return AbstractItem::field(field_name);
}



bool RootItem::isDirty() const
{
    return d->dirty;
}



void RootItem::setDirty(const bool &dirty)
{
    d->dirty = dirty;
}



void RootItem::setCustomData(const int &field, const QVariant &value)
{
    switch (field)
    {
    case FileData:
        d->filePath = value.toString();
        return;
    }
}



QVariant RootItem::customData(const int &field, int) const
{
    switch (field)
    {
    case FileData:
        return d->filePath;
    }

    return QVariant();
}



